﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO.Ports;

namespace envir2plotwatt.GUI.Configuration
{
    public partial class ChangePort : Form
    {
        string m_port;

        public string Port
        {
            get { return m_port; }
            set { m_port = value; }
        }

        public ChangePort(string currentPort)
        {
            m_port = currentPort;
            InitializeComponent();

            cbPort.Text = m_port;
        }

        private void ChangePort_Load(object sender, EventArgs e)
        {
            // get the list of available ports and add them to the combobox
            string[] ports = SerialPort.GetPortNames();

            cbPort.Items.Clear();

            foreach (string port in ports)
            {
                cbPort.Items.Add(port);
            }
        }

        private void btnAccept_Click(object sender, EventArgs e)
        {
            m_port = cbPort.Text;
            DialogResult = System.Windows.Forms.DialogResult.OK;
        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            DialogResult = System.Windows.Forms.DialogResult.Cancel;
        }
    }
}
